import type { shortTimeToken, shortTimeData, machineUpType } from '@/types/home'
import { http } from '../utils/http'
/**
 * * getShortTimeToken  临时token 接口  /temp_token
 */

export const getShortTimeToken = (data: shortTimeToken) => {
  return http<shortTimeData>({
    method: 'GET',
    url: '/auth/temp_token',
    data,
  })
}
/**
 * * getUserFlagApi 获取用户是否注册 flag 接口   /register/wechat/applet/exist
 */

export const getUserFlagApi = (data: any) => {
  return http<any>({
    method: 'GET',
    url: '/auth/register/wechat/applet/exist',
    data,
  })
}
/**
 * * getMachineDataApi  获取设备数据接口  /order/device/applet/coordinate/limit/summary
 */

export const getMachineDataApi = (data: machineUpType) => {
  return http<any>({
    method: 'GET',
    url: '/client/machine',
    data,
  })
}
/**
 * *   获取 领券中心列表 接口  /client/coupon/list
 */
export const getCouponsCnterListApi = (data: { pageNum: number; pageSize: number }) => {
  const cityName = JSON.parse(uni.getStorageSync('location'))?.location?.cityName || '杭州市'
  return http<any>({
    method: 'GET',
    url: '/client/coupon/list',
    data: { ...data, cityName },
  })
}

/**
 * *   获取 领取券 接口 /client/coupon/acquire
 * @param couponId 优惠券 id
 */
export const postCouponIdApi = (couponId: number) => {
  const cityName = JSON.parse(uni.getStorageSync('location'))?.location?.cityName || '杭州市'
  return http<any>({
    method: 'POST',
    url: `/client/coupon/acquire/${couponId}`,
    data: { cityName },
  })
}

/**
 * *   获取 我的优惠券 接口/client/coupon/clientCoupons
 * @param couponId 优惠券 id
 */
export const getMyCouponsApi = (data: {
  status: number
  clientId?: string
  pageNum: number
  pageSize: number
}) => {
  return http<any>({
    method: 'GET',
    url: '/client/coupon/clientCoupons',
    data,
  })
}

/**
 * *   获取 弹窗 接口 /client/coupon/popup
 * @param marketingId 营销id
 * @param invitationClientId 邀请人id
 */
export const getPopupApi = (data?: { marketingId?: number; invitationClientId?: string }) => {
  const cityName = JSON.parse(uni.getStorageSync('location'))?.location?.cityName || '杭州市'
  return http<any>({
    method: 'GET',
    url: '/client/coupon/popup',
    data: { ...data, cityName },
  })
}

/**
 * *   获取 可用营业点 接口 /client/coupon/getOutlets
 */
export const getBusinessPremisesApi = (data: { couponId: string }) => {
  return http<any>({
    method: 'GET',
    url: '/client/coupon/getOutlets',
    data,
  })
}
/**
 * *   获取 banner 图片 接口 /client/miniBanner
 */
export const getBannerListApi = (cityName?: string) => {
  return http<any>({
    method: 'GET',
    url: `/client/miniBanner?cityName=${cityName}`,
  })
}

/**
 * *   首页-领券中心-上新图标 接口/client/coupon/list/newIcon
 */
export const getToNewApi = () => {
  const cityName = JSON.parse(uni.getStorageSync('location'))?.location?.cityName || '杭州市'
  return http<any>({
    method: 'GET',
    url: '/client/coupon/list/newIcon',
    data: { cityName }
  })
}

/**
 * *   首页-优惠券倒计时 接口 /client/coupon/countdown
 */
export const getCountdownCouponsApi = () => {
  return http<any>({
    method: 'GET',
    url: '/client/coupon/countdown',
  })
}
/**
 * *   首页-金刚区 接口
 */
export const getMiniJinGangApi = () => {
  return http<any>({
    method: 'GET',
    url: '/client/miniJinGang/list',
  })
}
/**
 * *   首页-金刚区 接口
 */
export const getIsFirstOrderApi = () => {
  return http<any>({
    method: 'GET',
    url: '/client/order/isFirstOrder',
  })
}
